package bingo.spring.jndi;

import javax.naming.NamingException;

import org.springframework.jndi.JndiLocatorSupport;

import bingo.common.utils.ServerDetector;
/**
 * Mar 2, 2009 6:07:01 PM
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:解决不同Web服务器下获取数据源的问题
 * ChangeLog:
 */
public class JndiObjectFactoryBean extends org.springframework.jndi.JndiObjectFactoryBean {

	@Override
	protected Object lookup() throws NamingException {
			String jndiName = getJndiName();
			if(jndiName.startsWith(JndiLocatorSupport.CONTAINER_PREFIX)){
				if(ServerDetector.isWebLogic()){
					jndiName = jndiName.substring(JndiLocatorSupport.CONTAINER_PREFIX.length());
				}
			}else{
				if(ServerDetector.isTomcat()){
					jndiName = JndiLocatorSupport.CONTAINER_PREFIX + getJndiName();
				}
			}
			return lookup(jndiName, getExpectedType());
	}
}